package com.powernode.util;

import com.powernode.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * 认证工具类
 */
public class AuthUtils {

    /**
     * 获取登录用户认证对象
     * @return
     */
    public static SecurityUser getSecurityUser() {
        return (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取登录用户ID
     * @return
     */
    public static Integer getLoginUserId() {
        return getSecurityUser().getId();
    }

    /**
     * 获取登录用户角色集合
     * @return
     */
    public static Set<String> getSecurityUserRoleList() {
        return getSecurityUser().getRoleList();
    }
}
